Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Test stateless execution for cosmos-sdk baseapp using SMT-based fraudproofs #248

Closed
wants to merge 62 commits into from

Conversation

Manav-Aggarwal
Copy link
Member

@Manav-Aggarwal Manav-Aggarwal commented Aug 3, 2022

Description

As part of the fraudproof cycle described in #245, we'd like to be able to test stateless execution for a cosmos-sdk baseapp by using fraudproofs based on the new multistore with SMTs.

Parts covered from the cycle of a fraudproof:

Optimint Full Node (Producer of fraudproof)
3. The cosmos-sdk will simply execute the fraudulent block while logging all the states touched by the transaction. This minimial snapshot will be packaged as a fraudproof and passed back to optimint.

Optimint Full/Light Node (Verifier of fraudproof)
3. Now, it spins up a fresh cosmos-sdk and tells it to initialize with the fraudproof which is essentially a minimal snapshot sufficient to execute the fraudulent block.

Closes: #252


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • [] confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@Manav-Aggarwal Manav-Aggarwal added C: Cevmos Changes related to the cevmos branches block-fraud-proofs Block Fraud Proofs (Generation and verification) labels Aug 3, 2022
@Manav-Aggarwal Manav-Aggarwal self-assigned this Aug 3, 2022
@Manav-Aggarwal Manav-Aggarwal linked an issue Aug 3, 2022 that may be closed by this pull request
5 tasks
Comment on lines 15 to 19
// RocksDBBackend represents rocksdb (uses github.com/cosmos/gorocksdb)
// - EXPERIMENTAL
// - requires gcc
// - use rocksdb build tag (go build -tags rocksdb)
RocksDBBackend BackendType = "rocksdb"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: What is the reason for removing rocksdb here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

011f9d1
Had local issues with dependency management in macOS so added it, apologies, will revert this before merging (adding note in description)

Comment on lines 80 to 89
func (s *Store) GetSMTProof(key []byte) (*smt.SparseMerkleProof, error) {
if len(key) == 0 {
return nil, errKeyEmpty
}
proof, err := s.tree.Prove(key)
if err != nil {
return nil, err
}
return &proof, nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is wrong with above's GetProof?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The smt library accepts a raw proof only in the construction of deepSubTrees which are used when verifying a fraudProof before loading up a baseApp with it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm but this is about reading proofs, not writing proofs, no? Why does the SMT accepting raw proofs as writes matter?

baseapp/baseapp_test.go Outdated Show resolved Hide resolved
baseapp/baseapp_test.go Show resolved Hide resolved
baseapp/baseapp_test.go Outdated Show resolved Hide resolved
Comment on lines +18 to +19
traceListenMixin: newTraceListenMixin(),
substoreTraceListenMixins: make(map[types.StoreKey]*traceListenMixin),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the substoreTraceListenMixins, the traceListenMixin seems a bit redundant. Or is it still required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I view traceListenMixin as a tracer for Multistore and the substoreTraceListenMixins as tracers for each individual subStore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah OK. We can later make this a bit more explicit by renaming the variables or at least adding comments. Once the PR is feature complete.

@liamsi liamsi requested a review from adlerjohn August 5, 2022 03:14
Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't wait to see a simple single-round fraud proof in action!

@liamsi liamsi requested review from adlerjohn and removed request for adlerjohn August 5, 2022 14:09
@Manav-Aggarwal Manav-Aggarwal marked this pull request as ready for review August 5, 2022 17:58
@Manav-Aggarwal Manav-Aggarwal changed the title Implement a Single Round Fraudproof as a minimal integration test feat: Implement a Single Round Fraudproof as a minimal integration test Aug 5, 2022
@github-actions github-actions bot removed the C:orm label Aug 6, 2022
baseapp/fraudproof.go Show resolved Hide resolved
baseapp/fraudproof.go Outdated Show resolved Hide resolved
baseapp/options.go Outdated Show resolved Hide resolved
baseapp/baseapp_test.go Show resolved Hide resolved
baseapp/baseapp_test.go Outdated Show resolved Hide resolved
baseapp/baseapp_test.go Outdated Show resolved Hide resolved
store/tracekv/store.go Outdated Show resolved Hide resolved
store/tracekv/store.go Outdated Show resolved Hide resolved
store/tracekv/store.go Outdated Show resolved Hide resolved
store/tracekv/store.go Outdated Show resolved Hide resolved
store/v2alpha1/smt/store.go Outdated Show resolved Hide resolved
store/v2alpha1/smt/store.go Show resolved Hide resolved
storeKeyToSubstoreTraceBuf := make(map[stypes.StoreKey]*bytes.Buffer)
storeKeyToSubstoreTraceBuf[capKey2] = subStoreTraceBuf

fraudProof := generateFraudProof(cms, storeKeyToSubstoreTraceBuf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify a bit the order of operations to get to here? Does appB1.Commit() above commit state changes to disk? Does generateFraudProof get Merkle proofs against the post-execution root, or the pre-execution root?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calls to Commit() are irrelevant here, so I removed them for clarity. app.cms is able to access any state modified by block transactions.

generateFraudProof gets Merkle proofs against the post-execution root. We'd like the pre-execution root which is where rolling back the app's state to the previous block is needed.

@Manav-Aggarwal Manav-Aggarwal changed the title feat: Implement a Single Round Fraudproof as a minimal integration test feat: Test switching between a cosmos-sdk baseapp and fraudproof Aug 8, 2022
baseapp/baseapp_test.go Outdated Show resolved Hide resolved
@Manav-Aggarwal
Copy link
Member Author

everything is moved to cosmos-sdk-rollmint repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
block-fraud-proofs Block Fraud Proofs (Generation and verification) C: Cevmos Changes related to the cevmos branches C:Store
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test stateless execution for cosmos-sdk baseapp using SMT-based fraudproofs
4 participants